#ifndef _SPELL_HANDLER_H
#define _SPELL_HANDLER_H

class Player;
class Spell;
class GameObject;

typedef struct
{
	void (Spell::*effecthandler)();
} SpellEffectHandler;

struct TargetInfo
{
	ui64 targetUnit;
	ui64 targetItem;
	float srcX, srcY, srcZ;
	float destX, destY, destZ;
	ScopedAllocator<char> stringTarget;
	ui16 targetMask[2];

	TargetInfo() : stringTarget(255)
	{
		targetUnit = targetItem = 0;
		srcX = srcY = srcZ = destX = destY = destZ = 0;
		targetMask[0] = targetMask[1] = 0;
	}
};

class DLL_EXPORT Spell
{
	friend class Session;
	TargetInfo targets;
	SpellEntry* m_spellinfo;
	Player* p_caster;
	void SendCastResult(ui8 res);
	void Cancle(ui8 reason);
	ui8 cast_number;
	ui8 GetCastStatus();
	void FillTargets(ui64 guid, RealmPacket* source);
	bool HasAttribute(ui32 attribute) { return (m_spellinfo->Attributes & attribute); }
	void SendSpellStart();
	void SendSpellGo();
	void SpellEffectTeleport();
	bool UnitTargetSet;
	GameObject* m_pGoCastedFrom;
	ui32 casttime;
public:
	Spell(Player* caster, SpellEntry* ent, ui8 castnumber);
	void Start();
	void SetUnitTarget(ui64 guid);
	void SetSourceGameObject(GameObject* pObject) { m_pGoCastedFrom = pObject; }
	void SetCastTime(ui32 newtime) { casttime = newtime; }
	ui32 GetCastTime() { return casttime; }
	static void InitTable();
};

#endif